import request from '@/utils/request/index4.js'

// api地址
const api = {
	image: 'upload/image'
}

// 图片上传
export const image = (files, checkLogin = true) => {
	// 文件上传大小, 2M
	const maxSize = 1024 * 1024 * 2
	var parts =files[0].path.split('/');
	// 访问数组的最后一个元素
	var objectName = parts[parts.length - 1];
	// console.log(objectName);
	return new Promise((resolve, reject) => {
		request.urlFileUpload({
				name: 'file',
				files,
				maxSize,
				data: {
					objectName:objectName,
					checkLogin: Number(checkLogin)
				}
			})
			.then(result => {
				// console.log(result);
				resolve(result)
			})
			.catch(reject)
	})
}
// 图片上传
// import request from '@/utils/request/index4'

// // api地址
// const api = {
//   image: 'upload/image'
// }

// // 图片上传
// export const image = (files, checkLogin = true) => {
//   // 文件上传大小, 2M
//   const maxSize = 1024 * 1024 * 2
//   // 执行上传
//   return new Promise((resolve, reject) => {
//     request.urlFileUpload({ name: 'file', files, maxSize, data: { test: 123, checkLogin: Number(checkLogin) } })
//       .then(result => resolve(result.map(item => item.data.fileInfo.file_id), result))
//       .catch(reject)
//   })
// }